<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 遍历对象
        var arr = {
            name: "Peter",
            age: 18,
            address: "beijing"
        };
        for (var i in arr) {
            console.log(i);//得到的是属性：name,age,address 
        }
        for (var i in arr) {
            console.log(arr[i]);//得到的是属性值："Peter",18,"beijing"
        }

        // 遍历数组
        var arr = [1, 2, 3];

        for (i in arr) {
            console.log(i);//0,1,2
        }
        for (i in arr) {
            console.log(arr[i]);//1,2,3
        }


    </script>
</body>

</html>